package com.ehotting.mqbd.response.config;

import com.ehotting.mqbd.api.bean.MqApplicationContext;
import com.ehotting.mqbd.api.enums.DirectionEnum;
import com.ehotting.mqbd.api.enums.TopicEnum;
import com.ehotting.mqbd.core.helper.MQStringHelper;
import com.ehotting.mqbd.core.logger.MqMsgLogger;
import com.ehotting.mqbd.core.mq.consumer.ClientMQDataHandlerAble;
import com.ehotting.mqbd.core.mq.consumer.action.ConsumerResponseAction;
import com.ehotting.mqbd.core.config.MqbdCorePropertyConfig;
import com.ehotting.mqbd.core.mq.consumer.MessageConsumer;
import com.ehotting.mqbd.core.manager.ModuleManager;
import com.ehotting.mqbd.core.mq.consumer.action.CustomConsumerResponseAction;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@DependsOn("mqbdCorePropertyConfig")
public class ConsumerActionResponseConfig {


    @Bean(name="customConsumerResponseConcurrencyAction")
    public CustomConsumerResponseAction customConsumerResponseConcurrencyAction(MqApplicationContext mqApplicationContext,
                                                                          MqSyncFutureMapHelper mqSyncFutureMapHelper, ModuleManager moduleManager, MqMsgLogger mqMsgLogger, ClientMQDataHandlerAble clientMQDataHandler){
        CustomConsumerResponseAction action = new CustomConsumerResponseAction(
                mqSyncFutureMapHelper,
                mqApplicationContext,TopicEnum.CONCURRENCY,DirectionEnum.RESPONSE, moduleManager,mqMsgLogger,clientMQDataHandler);

        return action;
    }

    @Bean(name="responseConcurrencyMessageConsumer",initMethod = "start",destroyMethod = "shutdown")
    public MessageConsumer responseConcurrencyMessageConsumer(MqbdCorePropertyConfig mqbdCorePropertyConfig,
                                                              ConsumerResponseAction consumerResponseConcurrencyAction,
                                                              MqApplicationContext mqApplicationContext){
        MessageConsumer messageConsumer = new MessageConsumer(
                mqbdCorePropertyConfig.getConsumer(),
                MQStringHelper.createConsumerGroupAtConsumerApp(TopicEnum.CONCURRENCY , mqApplicationContext , DirectionEnum.RESPONSE),
                consumerResponseConcurrencyAction);

        return messageConsumer;
    }


}